package com.hnucm.cooklife.model;

import android.util.Log;

import com.blankj.utilcode.util.NetworkUtils;
import com.hnucm.cooklife.base.BaseModel;
import com.hnucm.cooklife.bean.me.DishColl;
import com.hnucm.cooklife.contract.meDishColl.Contract;

import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;

public class MeDishCollModel extends BaseModel implements Contract.IMeDishCollModel {


    public MeDishCollModel() {
        setCookies(false);
    }

    @Override
    public Observable<List<DishColl>> loadMeDishColl(int userId) {
        return mApiServer.loadMyDishColl(userId)
                .map(DishColl -> {
                    List<DishColl> DishCollList = new ArrayList<>();
                    DishColl.getData().stream().forEach(dataDTO -> {
                        DishColl DishCollDB = new DishColl();

                        DishCollDB.dishId = dataDTO.getDishId().getDishId();
                        DishCollDB.dishname = dataDTO.getDishId().getDishname();
                        DishCollDB.dishpic = dataDTO.getDishId().getDishpic();
                        DishCollDB.dishdesc = dataDTO.getDishId().getDishdesc();
                        DishCollDB.dishdone = dataDTO.getDishId().getDishdone();
                        DishCollDB.dishscore = dataDTO.getDishId().getDishscore();
                        DishCollDB.userid = dataDTO.getDishId().getUserid();
                        DishCollDB.icon = dataDTO.getDishId().getIcon();
                        DishCollDB.username = dataDTO.getDishId().getUsername();
                        DishCollList.add(DishCollDB);
                    });
                    return DishCollList;
                });
    }

    @Override
    public Observable<List<DishColl>> refreshMeDishColl(int userId) {
        return loadMeDishColl(userId);
    }
}
